package com.pmcc.core.web;

import com.pmcc.core.entity.security.Organization;
import com.pmcc.core.service.EmployeeService;
import com.pmcc.core.service.OrganizationService;
import com.pmcc.utils.AntdPage;
import com.pmcc.utils.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by tomas on 2018/4/9.
 */

@RestController()
@RequestMapping("api/v1/organizations")
@Api(value = "OrganizationController", description = "组织权限管理")
public class OrganizationController {
    @Autowired
    EmployeeService employeeService;
    @Autowired
    OrganizationService organizationService;



    @ApiOperation(value = "分页查询", httpMethod = "GET", notes = "组织列表", response = ResultBean.class)
    @GetMapping(value = "queryByPage")
    public ResultBean queryByPage(@ApiParam(required = false, name = "分页显示", value = "分页参数，默认第一页10条数据") AntdPage antdPage,
                                  @ApiParam(required = false, name = "实体对象", value = "实体参数") Organization model) {
        return organizationService.queryByPage(antdPage, model);
    }

    /**
     * 新增
     * @param organization
     * @return
     */
    @ApiOperation(value = "新增", httpMethod = "POST", notes = "新增组织", response = ResultBean.class)
    @PostMapping(value = "addOrganization")
    public ResultBean addEmployee(@ApiParam(required = true, name = "实体对象", value = "实体参数") @RequestBody Organization organization) {
        return organizationService.addOrganization(organization);
    }

    /**
     * 修改
     * @param map
     * @return
     */
    @ApiOperation(value = "修改保存", httpMethod = "PUT", notes = "保存修改组织信息", response = ResultBean.class)
    @PutMapping("updateById")
    public ResultBean edit(@ApiParam(required = true, name = "组织信息", value = "必须传输id") @RequestBody Map map) {
        return organizationService.update(map);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation(value = "id", httpMethod = "GET", notes = "假删除组织信息", response = ResultBean.class)
    @GetMapping("deleteById")
    public ResultBean delete(@ApiParam(required = true, name = "假除组织信息", value = "id") String id) {
        return organizationService.deleteById(id, 1);
    }



    /**
     * 点击组织，获得对应的人员
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询", httpMethod = "GET", notes = "查询对应的人员", response = ResultBean.class)
    @GetMapping(value = "queryById")
    public ResultBean queryById(@ApiParam(required = false, name = "分页显示", value = "分页参数，默认第一页10条数据") AntdPage antdPage,
                                @ApiParam(required = true, name = "id", value = "id") String id) {
        return organizationService.queryById(antdPage, id);
    }


    /**
     * 查询机构tree
     *人员管理 左侧树
     * @return
     */
    @ApiOperation(value = "查询组织机构树", httpMethod = "GET", notes = "查询组织机构树", response = ResultBean.class)
    @GetMapping("queryTree")
    public ResultBean queryTree(Organization organization) {
        ResultBean resultBean = new ResultBean();
        resultBean.setResultCode(ResultBean.SUCCESS);
        resultBean.setRows(organizationService.queryOrg(organization));
        return resultBean;


    }

    /**
     * 获取粗制机构管理 treeGrid list列表数据
     * @return
     */
    @ApiOperation(value = "查询组织机构treeGrid(组织机构list列表)", httpMethod = "GET", notes = "查询组织机构treeGrid（组织机构list列表）", response = ResultBean.class)
    @GetMapping("queryTreeGrid")
    public ResultBean queryTreeGrid() {
        ResultBean resultBean = new ResultBean();
        resultBean.setResultCode(ResultBean.SUCCESS);
        resultBean.setRows(organizationService.queryList());
        return resultBean;
    }
    @ApiOperation(value = "查询所有组织机构", httpMethod = "GET", notes = "查询所有组织机构", response = List.class)
    @GetMapping("queryAll")
    public List<Organization> queryAll(){
        return organizationService.queryAll();
    }

}

